package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Strategy;
import cn.wolfcode.luowowo.article.query.StrategyQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IStrategyService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/strategy")
public class StrategyController {

   @Reference
   private IStrategyService strategyService;

   @Reference
   private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")StrategyQuery qo, Model model){
        PageInfo pageInfo = strategyService.query(qo);
        model.addAttribute("pageInfo",pageInfo);

        return "strategy/list";
    }


    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public List<Destination> getDestByDeep(int deep){
        return destinationService.getDestByDeep(deep);

    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Strategy strategy){
        strategyService.saveOrUpdate(strategy);
        return new AjaxResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id){
        strategyService.delete(id);
        return new AjaxResult();
    }

}
